{extend name="common/main"/}
{block name="body"}
    <div class="main-title">
        <h2>在线更新</h2>
    </div>
    <div class="clearfix with-padding">

        <div class="clearfix">
            <div class="alert alert-primary-inverse with-icon">
                <i class="icon-info-sign"></i>
                <div class="content">每次升级自动备份原文件，路径 ：{$backupPath}</div>
            </div>
            <div class="alert alert-danger-inverse with-icon">
                <i class="icon-info-sign"></i>
                <div class="content">在线升级建议在系统设置中关闭网站，<a class="alert-link" href="{:url('admin/config/group',['id'=>4])}">点击这里关闭网站</a>！</div>
            </div>

            {if $upgrade}

            <div class="alert alert-warning-inverse with-icon">
                <i class="icon-info-sign"></i>
                <div class="content">在线升级请先备份数据库，防止升级失败数据丢失！</div>
            </div>

            <form id="migration" class="form-horizontal" role="form" method="post">
                <legend>检测到有可升级的版本</legend>
                <div class="form-group">
                    <label class="col-md-2 control-label">版本</label>
                    <div class="col-md-10">
                        <div class="form-control-static">
                            <p>当前版本{$localVersion}</p>
                            <p>最新版本{$cloudVersion['version']}</p>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">新版本升级说明</label>
                    <div class="col-md-10">
                        <div class="form-control-static">
                            {:htmlspecialchars_decode($cloudVersion['remark'])}
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">发布时间</label>
                    <div class="col-md-10">
                        <div class="form-control-static">

                            {$cloudVersion['create_time']|date='Y-m-d H:i:s'}

                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">更新协议</label>
                    <div class="col-md-10">
                        <div class="">
                            <div class="checkbox">

                                <input type="checkbox" name="box" id="agreement_0">
                                <label for="agreement_0">我已经做好了相关文件的备份工作</label>
                            </div>
                            <div class="checkbox">
                                <input type="checkbox" name="box" id="agreement_1">
                                <label for="agreement_1"> 认同官方的更新行为并自愿承担更新所存在的风险</label>
                            </div>
                            <div class="checkbox">
                                <input type="checkbox" name="box" id="agreement_2">
                                <label for="agreement_2"> 理解官方的辛勤劳动并报以感恩的心态点击更新按钮</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label"></label>
                    <div class="col-md-10">
                        <button type="button" id="oneupdate" class="btn btn-lg btn-primary">一键更新</button>
                    </div>
                </div>
            </form>
            <!--确认对话框-->
            <div class="modal modal-for-page fade" id="myModal">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                            <h4 class="modal-title">确认在线升级至 {$cloudVersion['version']}版</h4>
                        </div>
                        <div class="modal-body">
                            <p>少年！确认前可不要忽略文件和数据的备份哦～</p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" id="yesupdate" class="btn btn-primary">确认升级</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">我再想想...</button>
                        </div>
                    </div>
                </div>
            </div>
            <!--确认对话框END-->
            {else /}
                <div class="alert alert-info-inverse with-icon">
                    <i class="icon-info-sign"></i>
                    <div class="content">
                        <h3>当前版本：<span id="localVer">{$localVersion}</span></h3>
                        <h3>最新版本：<span id="cloudVer">{$cloudVersion['version']}</span></h3>
                    </div>
                </div>

                <div class="alert alert-warning-inverse with-icon">
                    <i class="icon-ok-sign"></i>
                    <div class="content"><h3>已经是最新版本。</h3></div>
                </div>
                <div class="checkButtonBox">
                    <button class="btn btn-block btn-lg btn-primary" id="checkVersion" type="button">重新检测</button>
                </div>
            {/if}
        </div>
    </div>

{/block}
{block name="script"}
<script>
    $(function(){
        $('#oneupdate').click(function(){
                var a = $("#agreement_0").is(':checked');
                var b = $("#agreement_1").is(':checked');
                var c = $("#agreement_2").is(':checked');
                if(a && b && c) {
                    $('#myModal').modal();
                } else {
                    toast.error("抱歉，更新前请仔细阅读并确认更新协议！");
                    return false;
                }
        });
        $('#yesupdate').click(function(){
            window.location.href = "{:url('update/start',['version' => $cloudVersion['version'],'app_name' => $appName])}"
        });
        $('#checkVersion').click(function(){
            $('#checkVersion').html('检测中...页面即将跳转');
            window.location.href='{:Url("admin/update/index")}';
        });
    });
</script>
{/block}

